package com.jsh.controller;

import com.jsh.pojo.Email;
import com.jsh.service.EmailService;
import com.jsh.util.DateConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/Email")
public class EmailController {
    @Autowired
    private EmailService emailService;
    @RequestMapping("/list")
    public String list(Model model){
        List<Email> list = emailService.selectAll();
        model.addAttribute("list",list);
        return "list_email";
    }
    @RequestMapping("/toUpdate")
    public String toUpdate(int emailId,Model model){
        Email email = emailService.selectByPrimaryKey(emailId);
        model.addAttribute("email",email);
        return "update_email";
    }
    @RequestMapping("/Update")
    public String Update(Email email){
        int i = emailService.updateByPrimaryKey(email);
        return "redirect:/Email/list";
    }
    @RequestMapping("/delete")
    public String delete(int emailId){
        int i = emailService.deleteByPrimaryKey(emailId);
        return "redirect:/Email/list";
    }
    @RequestMapping("/toInsert")
    public String toInsert(){
        return "addEmail";
    }
    @RequestMapping("/insert")
    public String Insert(Email email){
        int insert = emailService.insert(email);
        return "redirect:/Email/list";
    }

}
